Research
Security News
Threat Actor Exposes Playbook for Exploiting npm to Build Blockchain-Powered Botnets
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.
y-protocols
Advanced tools
The y-protocols npm package provides a set of protocols for building collaborative applications using Yjs, a high-performance CRDT (Conflict-free Replicated Data Type) framework. It includes protocols for awareness, WebRTC, and WebSocket communication, enabling real-time collaboration features such as shared editing and presence awareness.
Awareness Protocol
The Awareness protocol allows you to manage and track the presence and state of users in a collaborative session. This can be used to show who is online and their current activity or status.
const { Awareness } = require('y-protocols/awareness');
const awareness = new Awareness(doc);
// Set user state
awareness.setLocalStateField('user', { name: 'Alice' });
// Listen for changes in awareness
awareness.on('change', changes => {
console.log('Awareness changed:', changes);
});
WebRTC Protocol
The WebRTC protocol enables peer-to-peer communication for real-time collaboration. It allows users to connect directly to each other without the need for a central server.
const { WebrtcProvider } = require('y-protocols/webrtc');
const provider = new WebrtcProvider('my-room-name', doc);
// Listen for connection events
provider.on('synced', () => {
console.log('Synced with WebRTC peers');
});
WebSocket Protocol
The WebSocket protocol facilitates real-time communication over WebSocket connections. This is useful for scenarios where a central server is required to manage connections and data synchronization.
const { WebsocketProvider } = require('y-protocols/websocket');
const provider = new WebsocketProvider('wss://my-websocket-server', 'my-room-name', doc);
// Listen for connection events
provider.on('status', event => {
console.log('WebSocket connection status:', event.status);
});
Automerge is a library for building collaborative applications using CRDTs. It provides similar functionality to Yjs and y-protocols, allowing for real-time collaboration and conflict resolution. However, Automerge focuses more on simplicity and ease of use, while Yjs and y-protocols offer higher performance and more advanced features.
ShareDB is a real-time database backend based on Operational Transformation (OT). It allows multiple users to collaborate on the same data in real-time. While ShareDB uses OT instead of CRDTs, it provides similar real-time collaboration features and can be used with WebSocket for communication.
Gun is a decentralized, real-time, graph database that supports real-time data synchronization and offline-first capabilities. It provides similar real-time collaboration features as y-protocols but focuses on decentralized data storage and peer-to-peer communication.
Binary encoding protocols for syncing, awareness, and history information
This API is unstable and subject to change.
import * as awarenessProtocol from 'y-protocols/awareness.js'
The Awareness protocol implements a simple network agnostic algorithm that manages user status (who is online?) and propagate awareness information like cursor location, username, or email address. Each client can update its own local state and listen to state changes of remote clients.
Each client has an awareness state. Remote awareness are stored in a Map that maps from remote client id to remote awareness state. An awareness state is an increasing clock attached to a schemaless json object.
Whenever the client changes its local state, it increases the clock and
propagates its own awareness state to all peers. When a client receives a remote
awareness state, and overwrites the clients state if the received state is newer
than the local awareness state for that client. If the state is null
, the
client is marked as offline. If a client doesn't receive updates from a remote
peer for 30 seconds, it marks the remote client as offline. Hence each client
must broadcast its own awareness state in a regular interval to make sure that
remote clients don't mark it as offline.
const awareness = new awarenessProtocol.Awareness()
clientID:number
getLocalState():Object<string,any>|null
setLocalState(Object<string,any>|null)
setLocalStateField(string, any)
getStates():Map<number,Object<string,any>>
on('change', ({ added: Array<number>, updated: Array<number>
removed: Array<number> }, [transactionOrigin:any]) => ..)
on('update', ({ added: Array<number>, updated: Array<number>
removed: Array<number> }, [transactionOrigin:any]) => ..)
The MIT License © Kevin Jahns
FAQs
Yjs encoding protocols
The npm package y-protocols receives a total of 328,756 weekly downloads. As such, y-protocols popularity was classified as popular.
We found that y-protocols demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.
Security News
NVD’s backlog surpasses 20,000 CVEs as analysis slows and NIST announces new system updates to address ongoing delays.
Security News
Research
A malicious npm package disguised as a WhatsApp client is exploiting authentication flows with a remote kill switch to exfiltrate data and destroy files.